﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;

namespace Xiaov.SmartWeb.Infrastructure.Common
{
    public class General
    {
        #region "EasyUI弹出窗口、消息、弹出消息"
        /// <summary>
        /// 显示错误信息提示框：EasyUI_Messager
        /// </summary>
        /// <param name="page">this.page</param>
        /// <param name="title">Title</param>
        /// <param name="msg">错误信息</param>
        public static void ShowAlert(System.Web.UI.Page page, string title, string msg)
        {
            page.ClientScript.RegisterStartupScript(page.ClientScript.GetType(), "msg", "<script>$(document).ready(function() {$.messager.alert('" + title + "','" + msg + "','error')});</script> ");
        }
        /// <summary>
        /// 显示信息提示框：EasyUI_Messager
        /// </summary>
        /// <param name="page">this.page</param>
        /// <param name="msg">提示信息</param>
        public static void ShowAlert(System.Web.UI.Page page, string msg)
        {
            page.ClientScript.RegisterStartupScript(page.ClientScript.GetType(), "msg", "<script>$(document).ready(function() {$.messager.alert('操作提示','" + msg + "')});</script> ");
        }

        /// <summary>
        /// 弹出信息
        /// </summary>
        /// <param name="page"></param>
        /// <param name="title">窗口标题</param>
        /// <param name="msg">消息</param>
        /// <param name="Redirecturl">点击确认后转去特定地址</param>
        public static void ShowAlert(string title, string msg, string Redirecturl)
        {
            HttpContext.Current.Response.Clear();
            string html = ReadFileText(HttpContext.Current.Server.MapPath("/Resources/xiaovcn/templete/message.html"));
            string script =("<script>$(document).ready(function() {$.messager.alert('" + title + "','" + msg + "','info',function(){location.href='" + Redirecturl + "';})});</script> ");
            html = html.Replace("[$script$]", script);
            HttpContext.Current.Response.Write(html);
            HttpContext.Current.Response.End();
        }

        public static void ShowAlert(string msg)
        {
            ShowAlert("提示", msg, "#");
        }
        public static void ShowAlert(string msg,string redirectUrl)
        {
            ShowAlert("提示", msg, redirectUrl);
        }

        public static string ReadFileText(string absFilePath)
        {
            string txt = "";
            if (File.Exists(absFilePath))
                txt = File.ReadAllText(absFilePath, Encoding.UTF8);
            return txt;
        }
       

        /// <summary>
        /// 关闭弹出窗口：close_win方法在EasyuiWin.js内
        /// </summary>
        /// <param name="page"></param>
        /// <param name="rtnValue">返回值</param>
        /// <param name="refresh">刷新父页面:如果需要返回值请不要刷新页面</param>
        public static void CloseWin(System.Web.UI.Page page, string rtnValue, bool refresh)
        {
            page.ClientScript.RegisterStartupScript(page.ClientScript.GetType(), "msg", "<script>close_win('" + rtnValue + "','" + refresh + "');</script> ");
        }
        #endregion

        public static string GetUserId
        {
            get { return HttpContext.Current.User.Identity.Name; }
        }

       
    }
}
